package com.symbio.ishenapi.background.controller;

import com.symbio.ishenapi.background.model.TmDoctorAssistant;
import com.symbio.ishenapi.background.model.TmDoctorUser;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Map;

/**
 * @Author: chen
 * @Description:医肋医生对照控制层
 * @Date: Created in 17:06 2018/11/2
 * @Modified By:
 */
@RequestMapping("/TmDoctorAssistant")
public class TmDoctorAssistantController extends BaseController{


    /**
     * 展示列表分页查询
     */
    public void findList(){

        try {
            Map map = TmDoctorAssistant.dao.findList(getQueryModel());
            renderPageJsonRet(map.get("count"),map.get("data"));
        }catch (Exception e){
            renderJsonError(50002,"医生医肋对照查询");
        }
    }

    /**
     * 逻辑批量删除
     */
    public void deletes(){

        String ids = getPara("ids");
        try {
            TmDoctorAssistant.dao.deletes(ids);
            renderJsonError(50001,"医生对照删除");
        }catch (Exception ex){
            renderJsonError(50002,"医生对照表删除");
        }
    }

    /**
     * chen
     * 根据医生id和医肋id删除表数据
     */
    public void deletesByDoctorIdAssId(){
        try {
            String doctorIds = getPara("doctorId");
            String assIds = getPara("assId");
            TmDoctorAssistant.dao.deletesByDoctorIdAssId(doctorIds,assIds);
            renderJsonError(50001,"医生医助删除");
        }catch (Exception e){
            renderJsonError(50002,"医生医肋删除");
        }
    }

    /** chen
     * 根据用户类型查询医生表
     * page  起始页    必传参数
     * limit 条数      必传参数
     * phoneName  手机号或姓名
     * userType 用户类型 0.医生1.医肋   必传参数
     * hosId    医院ID
     * userId   选择的用户ID
     */
    public void findDoctorList(){
        String hosId = getPara("hosId");
        String phoneName = getPara("phoneName");
        String userType = getPara("userType");
        String userId = getPara("userId");
        //hosId = "15";//暂时写死 ，待完善
        try {
            Map map = TmDoctorUser.dao.findDoctorListByType(getQueryModel(),phoneName,userType,hosId,userId);
            renderPageJsonRet(map.get("count"),map.get("data"));
        }catch (Exception e){
            renderJsonError(50002,"医肋列表查询");
        }
    }


    /**
     * 医生医生对应保存
     * doctorIds        医生ids集合必传
     * assistantsIds    医肋ids集合必传
     */
    public void saveDoctorAssistant(){

        try {
            String doctorIds = getPara("doctorIds");
            String assistantsIds = getPara("assistantsIds");
            TmDoctorAssistant.dao.saveDoctorAssistant(doctorIds,assistantsIds);
            renderJsonError(50001,"医生医肋保存");
        }catch (NumberFormatException ex){
            renderJsonError(50002,"数据不能为空");
        }
        catch (Exception e){
            renderJsonError(50002,"医生医肋保存");
        }
    }

    /**chen
     * 获取医生对应医肋列表查询
     */
    public void findDoctorToAssistantList(){
        try {
            String hosId = getPara("hosId");
            //hosId = "15";
            Map map = TmDoctorAssistant.dao.findDoctorToAssistantList(getQueryModel(),hosId);
            renderPageJsonRet(map.get("count"),map.get("data"));
        }catch (Exception e){
            renderJsonError(50002,"获取医生对应医肋列表查询");
        }
    }

    /**chen
     * 获取医肋对应医生列表查询
     */
    public void findAssistantToDoctorList(){
        try {
            String hosId = getPara("hosId");
            //hosId = "15";
            Map map = TmDoctorAssistant.dao.findAssistantToDoctorList(getQueryModel(),hosId);
            renderPageJsonRet(map.get("count"),map.get("data"));
        }catch (Exception e){
            renderJsonError(50002,"获取医肋对应医生列表查询");
        }
    }
}
